//
//  ChangeNIckeViewController.m
//  XDLookPic
//
//  Created by wanglong8889@126.com on 14-8-25.
//  Copyright (c) 2014年 XD-XY. All rights reserved.
//

#import "ChangeNIckeViewController.h"

#import "My_EditInfoViewController.h"


@interface ChangeNIckeViewController ()

@end

@implementation ChangeNIckeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.titleLabel.text = @"修改昵称";
    
    
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightButton setTitle:@"保存" forState:UIControlStateNormal];
    [rightButton setTitleColor:self.titleLabel.textColor forState:UIControlStateNormal];
    [rightButton setFrame:CGRectMake(520/2.0f, 13+aHeight, 60, 25)];
    rightButton.titleLabel.font = [UIFont systemFontOfSize:17.5];
    [rightButton addTarget:self action:@selector(saveNickNmae) forControlEvents:UIControlEventTouchUpInside];
    
    [self.navigationBarView addSubview:rightButton];
    
    [self initNickViews];
}

-(void)initNickViews{
    
    UIImageView *nicView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, 320, 44)];
    
    nicView.userInteractionEnabled = YES;
    
    nicView.image = [UIImage imageNamed:@"nickchange_bg"];
    
    
    nickTf = [[UITextField alloc] initWithFrame:CGRectMake(10, 7, 300, 30)];
    
    nickTf.text = _name;
    
    nickTf.clearButtonMode = UITextFieldViewModeWhileEditing;
    
    [nickTf becomeFirstResponder];
    
    [nicView addSubview:nickTf];
    
    [self.contentView addSubview:nicView];
    
    UILabel *tishiLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, nicView.frame.origin.y+nicView.frame.size.height+10, 300, 80)];
    
    tishiLabel.backgroundColor = [UIColor clearColor];
    
    tishiLabel.textColor = [UIColor grayColor];
    
    tishiLabel.numberOfLines = 0;
    
    tishiLabel.font = [UIFont systemFontOfSize:14.0];
    
    tishiLabel.text = @"格式：汉字 英文 数字 下划线组成，2-8位";
    
    [self.contentView addSubview:tishiLabel];
    
    
    
    
}

-(void)saveNickNmae{
    
    
    if (!IS_NOT_EMPTY(nickTf.text)) {
        [XDTools showTips:@"抱歉，昵称不能为空" toView:self.view];
        return;
    }else if ([nickTf.text isEqualToString:_name]) {
            [self backPrePage];
    }else{
        
        if (nickTf.text.length<2) {
            [XDTools showTips:@"抱歉，昵称太短" toView:self.view];
            
            return;
        }
        if (nickTf.text.length>8) {
            [XDTools showTips:@"抱歉，昵称太长" toView:self.view];
            
            return;
        }
        
        

       NSString *customId = [[NSUserDefaults standardUserDefaults] objectForKey:kMY_USER_ID];
        
        if (customId == nil) {
            customId = @"";
        }
        
        NSDictionary *requestDic = @{@"CustomerID":customId,
                                     @"NickName":nickTf.text};
        [self.editVC editInfosData:requestDic];
        
        [self backPrePage];
        
    }
    
   
   
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
